package com.ouc.openplatform.zykt.authManage.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ouc.openplatform.pojo.EUDataGridResult;
import com.ouc.openplatform.zykt.authManage.dto.NJ_RoleInfoDTO;
import com.ouc.openplatform.zykt.authManage.model.NJ_RoleInfo;
import com.ouc.openplatform.zykt.authManage.service.NJ_ClientRoleInfoService;
import com.ouc.openplatform.zykt.authManage.service.NJ_RoleInfoService;
public class NJ_ClientRoleInfoServiceImpl implements NJ_ClientRoleInfoService {
	private NJ_RoleInfoService nj_roleInfoService;

	public NJ_RoleInfoService getNj_roleInfoService() {
		return nj_roleInfoService;
	}

	public void setNj_roleInfoService(NJ_RoleInfoService nj_roleInfoService) {
		this.nj_roleInfoService = nj_roleInfoService;
	}

	//1.增加角色信息
	@Override
	public int saveRoleInfo(NJ_RoleInfoDTO roleinfoDTO) {
		//flag 0:添加失败  1:添加成功  2.角色信息已经存在
		int flag = 0;
		//判断角色信息是否存在-----0:不存在    1:存在
		int i = nj_roleInfoService.IsRoleName(roleinfoDTO.getRolename());
		if (i == 0) {
			NJ_RoleInfo roleinfo = new NJ_RoleInfo();
	        roleinfo.setAddtime(new Date());
			roleinfo.setRolename(roleinfoDTO.getRolename());
			roleinfo.setAdduser(roleinfoDTO.getAdduser());
			flag = nj_roleInfoService.saveRoleInfo(roleinfo);
		} else {
			flag = 2;
		}
		return flag;
	}
	
    //2.删除角色信息
	@Override
	public int deleteRoleInfo(int roleid) {
		int flag = nj_roleInfoService.deleteRoleInfo(roleid);
		return flag;
	}

	//3.更新角色信息
	@Override
	public int updateRoleInfo(NJ_RoleInfoDTO roleinfoDTO) {
		int flag = 0;
		int i = nj_roleInfoService.IsRoleName(roleinfoDTO.getRolename());
		if (i == 0) {
			NJ_RoleInfo roleinfo = new NJ_RoleInfo();
			SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			try {
				Date date = myFmt.parse(roleinfoDTO.getAddtime().toString());
				roleinfo.setAddtime(date);
			} catch (ParseException e) {
				e.printStackTrace();
			}
			roleinfo.setAdduser(roleinfoDTO.getAdduser());
			roleinfo.setRolename(roleinfoDTO.getRolename());
			roleinfo.setId(roleinfoDTO.getId());
			flag = nj_roleInfoService.updateRoleInfo(roleinfo);
		} else {
			flag = 2;
		}
		return flag;
	}
    
	//4.查询角色信息
	@Override
	public EUDataGridResult getAllRoleInfoByPage(int page, int rows) {
		
		return nj_roleInfoService.getRoleInfo(null, page, rows);
	}
	
	//5.判断角色是否存在
	@Override
	public int IsRoleName(String rolename, int id) {
		int i = nj_roleInfoService.IsRoleName(rolename);
		return i;
	}

	//6.查询所有角色权限信息-----sxl
	@Override
	public List<NJ_RoleInfo> getAllRoleInfo(NJ_RoleInfo roleInfo) {
		return nj_roleInfoService.getAllRoleInfo(roleInfo);
	}


}
